﻿using NLog;
using Quartz;
using SqlSugar;
using System.Threading.Tasks;

namespace JobSchedule.Base
{
    public abstract class JobBase : IJob
    {
        public Logger logger = LogManager.GetCurrentClassLogger();
        private SqlSugarClient _sqlsugarClient;
        public SqlSugarClient db
        {
            get
            {
                if (_sqlsugarClient == null)
                {
                    var conn = "";
                    var db = new SqlSugarClient(
                    new ConnectionConfig()
                    {
                        ConnectionString = conn,
                        DbType = DbType.MySql,
                        IsAutoCloseConnection = true
                    });
                    _sqlsugarClient = db;
                }
                return _sqlsugarClient;
            }
        }

        private static readonly Task CompletedTask = Task.FromResult<object>(null);

        public Task Execute(IJobExecutionContext context)
        {
            ExecuteJob(context);
            return CompletedTask;
        }

        public abstract void ExecuteJob(IJobExecutionContext context);
    }
}
